package org.vshe.improve.spring.prospring3.ch6;

import org.aopalliance.aop.Advice;
import org.springframework.aop.Advisor;
import org.springframework.aop.Pointcut;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.DefaultPointcutAdvisor;

public class SimplePointcutTest {
	
	public static void main(String[] args) {
		ProxyFactory factory = new ProxyFactory();
		BeanOne beanOne = new BeanOne();
		BeanTwo beanTwo = new BeanTwo();
		
		Pointcut pointcut = new SimplePointcut();
		Advice advice = new SimpleAdvice();
		Advisor advisor = new DefaultPointcutAdvisor(pointcut, advice);
		
		factory.addAdvisor(advisor);
		factory.setTarget(beanOne);
		BeanOne proxyOne = (BeanOne) factory.getProxy();
		
		factory = new ProxyFactory();
		
		factory.setTarget(beanTwo);
		factory.addAdvisor(advisor);
		BeanTwo proxyTwo = (BeanTwo) factory.getProxy();
		
		proxyOne.writeMessage();
		proxyTwo.writeMessage();
	}

}
